package org.jinyan.quartz;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.ScheduleBuilder;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class QuartzManager {

	public static void main(String[] args) throws SchedulerException,
			ClassNotFoundException {
		Class jobClass = Class.forName("org.jinyan.quartz.WorkJob");
		testSimpleTrigger("testJob", "groupName", "triggerName", jobClass, 10,
				10);
	}

	public static void testSimpleTrigger(String jobName, String groupname,
			String triggerName, Class jobClass, int intervalSeconds,
			int repeatCount) throws SchedulerException, ClassNotFoundException {
		System.err.println("test Start");
		SchedulerFactory sf = new StdSchedulerFactory();
		Scheduler sch = sf.getScheduler();

		JobDetail job = JobBuilder.newJob(jobClass)
				.withIdentity(jobName, groupname).build();
		Trigger trigger = TriggerBuilder
				.newTrigger()
				.withIdentity(triggerName, groupname)
				.startNow()
				.withSchedule(
						SimpleScheduleBuilder.simpleSchedule()
								.withIntervalInSeconds(intervalSeconds)
								.withRepeatCount(repeatCount)).build();
		sch.scheduleJob(job, trigger);
		sch.start();
		System.err.println("test over");

	}
	
}
